package com.cyl.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.wms.convert.PurchaseOrderDetailsConvert;
import com.cyl.wms.convert.ReceiptOrderDetailConvert;
import com.cyl.wms.domain.PurchaseOrderDetails;
import com.cyl.wms.domain.ReceiptOrderDetail;
import com.cyl.wms.mapper.PurchaseOrderDetailsMapper;
import com.cyl.wms.pojo.query.PurchaseOrderDetailsQuery;
import com.cyl.wms.pojo.vo.PurchaseOrderDetailsVo;
import com.cyl.wms.pojo.vo.ReceiptOrderDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;

/**
* @author zhipeng
* @description 针对表【wms_purchase_order_details】的数据库操作Service
* @createDate 2024-02-14 21:52:34
*/
@Service
public class PurchaseOrderDetailsService  {
    @Autowired
    private PurchaseOrderDetailsMapper purchaseOrderDetailsMapper;

    @Autowired
    private PurchaseOrderDetailsConvert convert;
    public int insert(PurchaseOrderDetails purchaseOrderDetails) {
        purchaseOrderDetails.setCreateTime(LocalDateTime.now());
        return purchaseOrderDetailsMapper.insert(purchaseOrderDetails);
    }
    public List<PurchaseOrderDetails> selectList(PurchaseOrderDetailsQuery query) {
        QueryWrapper<PurchaseOrderDetails> qw = new QueryWrapper<>();
        String orderNumber = query.getOrderNumber();
        if (orderNumber != null) {
            qw.eq("order_number", orderNumber);
        }
        return purchaseOrderDetailsMapper.selectList(qw);
    }
    public List<PurchaseOrderDetailsVo> toVos(List<PurchaseOrderDetails> items) {
        List<PurchaseOrderDetailsVo> list = convert.dos2vos(items);
        list.forEach(itemVO -> {
            List<String> place = new LinkedList<>();
            if (itemVO.getOrderNumber() != null) {
                place.add(itemVO.getOrderNumber());
            }
//            itemVO.setPlace(place);
        });
        return list;
    }
}
